package com.huanzhidadi.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class OrderDelayedConfig {

    /**
     * 延迟消息交换机
     * @return
     */
    @Bean
    public CustomExchange orderDelayExchange() {
        Map<String, Object> args = new HashMap<>();
        // 设置自定义交换器路由消息的类型，direct类似direct交换器路由消息的模式，也可以传递topic、fanout,或者其它插件提供的自定义的交换器类型
        args.put("x-delayed-type", "direct");
        return new CustomExchange("order_delayed_exchange", "x-delayed-message", true, false, args);
    }

    @Bean
    public Queue orderDelayedQueue() {
        return new Queue("order_delay_queue");
    }
    /**
     * 延迟队列绑定交换器
     */
    @Bean
    public Binding bindingOrderDelayExchangeQueue(){
        return BindingBuilder.bind(orderDelayedQueue()).to(orderDelayExchange()).with("order_delay_queue").noargs();
    }
}
